//
//  Waypoint.m
//  CommandCenter08
//
//  Created by Matt Roman on 7/1/08.
//  Copyright 2008 University of Oklahoma. All rights reserved.
//

#import "Waypoint.h"


@implementation Waypoint
- (id)initWithPoint:(Point3D)p andID:(int)i
{
	self = [super init];
	point = p;
	uuid = i;
	science = WPScienceNone;
	state = WPStateNew;
	distance = 0;
	traveled = 0;
	time = nil;
	notes = nil;
	return self;
}
- (id)initWithPoint:(Point3D)p andID:(int)i dist:(float)d
{
	self = [super init];
	point = p;
	uuid = i;
	science = WPScienceNone;
	state = WPStateNew;
	distance = d;
	traveled = 0;
	time = nil;
	notes = nil;
	return self;
}
- (id)initWithLatLon:(LatLonCoord)llc andID:(int)i
{
	self = [super init];
	coordinates = llc;
	uuid = i;
	science = WPScienceNone;
	state = WPStateNew;
	distance = 0;
	traveled = 0;
	time = nil;
	notes = nil;
	return self;
}
-(void)setPoint:(Point3D)p
{
	point = p;
}
-(Point3D)point
{
	return point;
}
- (LatLonCoord)coordinates
{
	return coordinates;
}
- (void)setLatLonCoordinates:(LatLonCoord)ll
{
	coordinates.lat.dd = ll.lat.dd;
	coordinates.lon.dd = ll.lon.dd;
}
-(double)Xcord
{
	return point.x;
}
-(void)setXcord:(double)x
{
	point.x = x;
}
-(double)Ycord
{
	return point.y;
}
-(void)setYcord:(double)y
{
	point.y = y;
}
-(void)setState:(int)s
{
	state = s;
}
-(int)state
{
	return state;
}
- (NSImage *)stateIcon
{
	NSImage *result = nil;
	switch (state) {
		case WPStateNew:
			result = [NSImage imageNamed:@"white"];
			break;
		case WPStateOld:
			result = [NSImage imageNamed:@"barbar"];
			break;
		case WPStateCurrent:
			result = [NSImage imageNamed:@"green"];
			break;
		case WPStateSkipped:
			result = [NSImage imageNamed:@"red"];
			break;
		default:
			break;
	}
	return result;
}
-(void)setUuid:(int)i
{
	uuid = i;
}
-(int)uuid
{
	return uuid;
}
-(void)setScience:(int)type
{
	science = type;
}
-(int)science
{
	return science;
}
-(NSString *)scienceString
{
	NSString *result = nil;
	switch (science) {
		case WPScienceNone:
			result = [NSString stringWithString:@""];
			break;
		case WPSciencePanorama:
			result = [NSString stringWithString:@"Panorama"];
			break;
		case WPScienceSpectra:
			result = [NSString stringWithString:@"Spectra Analysis"];
			break;
		case WPSciencePanoramaAndSpectra:
			result = [NSString stringWithString:@"Panorama and Spectra"];
			break;
		default:
			result = nil;
			break;
	}
	return result;
}
-(void)setDistance:(float)d
{
	distance = d;
}
-(float)distance
{
	return distance;
}
-(void)setTraveled:(float)d
{
	traveled = d;
}
-(float)traveled
{
	return traveled;
}
-(void)setWPTime:(NSDate *)t
{
	id oldtime = time;
	time = [t retain];
	[oldtime release];
}
-(NSDate*)time
{
	return time;
}
-(NSString*)timeHMS
{
	return [time descriptionWithCalendarFormat:@"%H:%M:%S" timeZone:nil locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
}
- (NSString*)notes
{
	return notes;
}
- (void)setNotes:(NSString *)note
{
	if(note == nil) return;
	if([note isEqual:@""]) {
		[notes release];
		notes = nil;
	}
	else {
		if(notes) [notes release];
		notes = [[NSString alloc] initWithString:note];
	}
}
@end
